package com.controller.experiment;

import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//自定义适配器：指定调用MyController中的myTest方法
public class MyControllerAdapter implements HandlerAdapter {

    //判断是否符合自定义控制器接口类型，满足要求则调用handle方法
    @Override
    public boolean supports(Object handler) {

        return (handler instanceof MyController);
    }

    //调用自定义控制器的指定方法
    @Override
    public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        return ((MyController) handler).myTest(request,response);
    }


    @Override
    public long getLastModified(HttpServletRequest request, Object handler) {
        return 0;
    }
}
